<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>器械采购计划详情</title>
<link rel="stylesheet" type="text/css" href="<c:url value="/css/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css" href="<c:url value="/css/themes/icon.css"/>">
<script type="text/javascript" src="<c:url value="/js/jquery.min.js"/>"></script>
<script type="text/javascript" src="<c:url value="/js/jquery.easyui.min.js"/>"></script>
<script type="text/javascript" src="<c:url value="/js/easyui-lang-zh_CN.js"/>"></script>
<style>
* {
	font-size: 12px;
}
.item{
		margin-top: 5px;
	}
</style>
</head>
<body>
	<script type="text/javascript">
	var editIndex = undefined;
	//结束正在编辑的行
	function endEditing() {
		if (editIndex == undefined) {
			return true
		}
		if ($('#tab_equprcplan').datagrid('validateRow', editIndex)) {
			$('#tab_equprcplan').datagrid('endEdit', editIndex);
			editIndex = undefined;
			return true;
		} else {
			return false;
		}
	}
	//事件：单击单元格的事件
	function onClickCell(index, field) {
		if (editIndex != index) {
			if (endEditing()) {
				$('#tab_equprcplan').datagrid('selectRow', index).datagrid('beginEdit',
						index);
				var ed = $('#tab_equprcplan').datagrid('getEditor', {
					index : index,
					field : field
				});
				if (ed) {
					($(ed.target).data('textbox') ? $(ed.target).textbox(
							'textbox') : $(ed.target)).focus();
				}
				editIndex = index;
			} else {
				setTimeout(function() {
					$('#tab_equprcplan').datagrid('selectRow', editIndex);
				}, 0);
			}
		}
	}
	//结束编辑，同步数据
	function onEndEdit(index, row) {
		var ed = $(this).datagrid('getEditor', {
			index : index,
			field : 'equName'
		});
		row['equName'] = $(ed.target).combobox('getText');
		
		var ed = $(this).datagrid('getEditor', {
			index : index,
			field : 'equUnit'
		});
		row['equUnit'] = $(ed.target).combobox('getText');
		
		var ed = $(this).datagrid('getEditor', {
			index : index,
			field : 'equBatch'
		});
		row['equBatch'] = $(ed.target).combobox('getText');
		
		var ed = $(this).datagrid('getEditor', {
			index : index,
			field : 'equSupplierName'
		});
		row['equSupplierName'] = $(ed.target).combobox('getText');
	}
	//添加行
	function append() {
		/* var equname = $("#equname").combogrid('getValue');
		var equpn = $("#equpn").numberspinner('getValue');
		var equep = $("#equep").numberbox('getValue');
		var equu = $("#equu").combobox('getValue');
		var equb = $("#equb").numberspinner('getValue');
		var equsn = $("#equsn").combogrid('getValue'); */
		if (endEditing()) {
			$('#tab_equprcplan').datagrid('appendRow', {
				'equName' : [],
				'equPrcNumber' : [],
				'equExpectedPrice' : [],
				'equUnit' : [],
				'equBatch' : [],
				'equSupplierName' : []
			});
			editIndex = $('#tab_equprcplan').datagrid('getRows').length - 1;
			$('#tab_equprcplan').datagrid('selectRow', editIndex).datagrid('beginEdit',
					editIndex);
		}
	} 

	//删除行
	function removeit() {
		if (editIndex == undefined) {
			return
		}
		$('#tab_equprcplan').datagrid('cancelEdit', editIndex).datagrid('deleteRow',
				editIndex);
		editIndex = undefined;
	}

	//应用
	function accept() {
		if (endEditing()) {
			endEditing();
		}
	}

	//撤消
	function reject() {
		$('#tab_equprcplan').datagrid('rejectChanges');
		editIndex = undefined;
	}

	//获取数据
	function getChanges() {
		var rows = $('#tab_equprcplan').datagrid('getChanges');
		alert(rows.length + ' rows are changed!');
	}

	//提交采购计划
	function savePlan() {
		//将datagrid中的数据行保存到隐式表单域中
		//1、获取新增的数据行
		var rows = $('#tab_equprcplan').datagrid('getChanges');
		console.log(JSON.stringify(rows));

		//为每一行生成对应的隐藏表单域
		for (var i = 0; i < rows.length; i++) {
			generateHidden(rows[i], "equName", i);
			generateHidden(rows[i], "equPrcNumber", i);
			generateHidden(rows[i], "equExpectedPrice", i); 
			generateHidden(rows[i], "equUnit", i);
			generateHidden(rows[i], "equBatch", i); 
			generateHidden(rows[i], "equSupplierName", i);

		}
		
		 var form_equprcdetail = $("#form_equprcdetail");
		//提交表单
		form_equprcdetail.form("submit", {
			success : function(v) {
				$.messager.alert('提示', "提交成功");
				$(":hidden[x='y']").remove();
				$(this).form("clear");
			}
		});
	}
		
	function generateHidden(row, name, i) {
		var form_equprcdetail = $("#form_equprcdetail");
		$("<input type='hidden' x='y'>").attr("name",
				"details[" + i + ']' + '.planDetail' + name).val(
				row['details.planDetail' + name]).appendTo(form_equprcdetail);
	}	
	
		$(function(){
			$("#equsn").combogrid({
				label:'供应商:', 
				editable: false,
<<<<<<< HEAD
				width:'45%',
				labelWidth:'60',
				panelWidth: '450',
				panelHeight:'auto',
				url:'findEquipmentSupplierByPage',
				pagination: true,
				pageSize: 10,
				pageList: [5, 10, 15, 20],
				idField: 'equSupplierId',
				textField: 'equSupplierName',
				columns:[[
					      {field:'equSupplierId',title:'供应商ID',checkbox:true,width:60},
					      {field:'equSupplierName',title:'供应商名称',width:100,align:'center'},
					      {field:'equSupplierPhone',title:'供应商电话',width:100,align:'center'},
					      {field:'equSupplierAddress',title:'供应商地址',width:100,align:'center'},
					      {field:'equHead',title:'负责人',width:80,align:'center'}
					    ]] 
			});
			
			$("#equa").combogrid({
				label:'采购员:',
				width:'45%',
				labelWidth:'60',
				panelWidth: '300',
				panelHeight: '350',
				url:'findEmpByPage',
				editable: false,
				pagination: true,
				pageSize: 10,
				pageList: [5, 10, 15, 20],
				idField: 'employeeName',
				textField: 'employeeName',
				columns:[[
							 {field:'employeeName',title:'姓名',width:90},
			                 {field:'depName',title:'部门',width:100},
			                 {field:'employeeJob',title:'职位',width:100}
	            		]]
			});
			
		});
	</script>
	<form id="form_equprcdetail" action="do_equprcdetail" method="post">
		<table id="tab_equprcdetail" width="100%" style="background: rgb(236, 243, 255); padding: 10px; border-radius: 5px;">
				<tr>
					<td style="width:30%">
						<input id="equat" class="easyui-datebox" data-options="
								 label:'到货日期:',
								 width:'45%',
								 editable: false,
								 labelWidth:'60'" />
					</td>	
					<td style="width:30%">
						<input id="equa" name="equApprover"/>
					</td>
					<td style="width:30%">
						<select id="equsn" name="equSupplierName"></select>
					</td>
				</tr>
		</table>
		
		<div style="margin: 5px;">
			<div id="tt" class="easyui-tabs" style="width:70%; margin-top: 10px;"
				data-options="plain:true,narrow:true">
				<div title="采购计划明细" style="padding:10px">
				<form id="form2_equprcdetail" action="" method="post">
					<table id="tab_equprcplan" class="easyui-datagrid" style="height: auto;width:80%" data-options="
								iconCls: 'icon-edit',
								singleSelect: true,
								toolbar: '#toolbar_proprcdetail',
								method: 'get',
								width: '80%'">
						<thead>
							<tr>
								<th data-options="field:'equName',width:'16%',align:'center',editor:{
										type:'combogrid',
										options:{
										width:'45%',
										labelWidth:'60',
										panelWidth: '290',
										panelHeight: 'auto',
										editable: false,
										url:'findequprplanByequname',
										pagination: true,
										pageSize: 10,
										pageList: [5, 10, 15, 20],
										idField: 'equName',
										textField: 'equName',
										multiple: true,
										fitColumns: true,
										columns:[[
												    {field:'equPrcPlanId',title:'编号',checkbox:true,width:80},
										      		{field:'equName',title:'器械名称',width:100,align:'center'},
										      		{field:'equAppStatus',title:'审批状态',width:100,align:'center'}
										    	]]
										}}">器械名称</th>
									<th data-options="field:'equPrcNumber',width:'16%',editor:'textbox',editor:{type:'numberbox',options:{precision:2}},align:'center'">采购数量</th>
									<th data-options="field:'equExpectedPrice',width:'16%',editor:{type:'numberbox',options:{precision:2}},align:'center'">单价</th>
									<th data-options="field:'equUnit',width:'16%',align:'center',editor:{
												type:'combobox',
												options:{
												valueField:'label',
												textField:'value',
												editable: false,
												panelHeight: 'auto',
												data: [{label:'个',value:'个'},{label:'台',value:'台'},{label:'把',value:'把'}]
														}
												}">单位</th>
									<th data-options="field:'equBatch',width:'16%',align:'center',editor:{
												type:'combobox',
												options:{
												valueField:'label',
												textField:'value',
												editable: false,
												panelHeight: 'auto',
												data: [{label:'1',value:'1'},{label:'2',value:'2'},{label:'3',value:'3'}]
														}
												}">批次</th>
									<th data-options="field:'equSupplierName',width:'16%',align:'center',editor:{
												type:'combogrid',
												options:{
												panelWidth: '450',
												panelHeight:'auto',
												editable: false,
												url:'findEquipmentSupplierByPage',
												pagination: true,
												pageSize: 10,
												pageList: [5, 10, 15, 20],
												idField: 'equSupplierId',
												textField: 'equSupplierName',
												columns:[[
													      {field:'equSupplierId',title:'供应商ID',checkbox:true,width:60},
													      {field:'equSupplierName',title:'供应商名称',width:100,align:'center'},
													      {field:'equSupplierPhone',title:'供应商电话',width:100,align:'center'},
													      {field:'equSupplierAddress',title:'供应商地址',width:100,align:'center'},
													      {field:'equHead',title:'负责人',width:80,align:'center'}
													    ]]
										}}">供应商</th>
								</tr>
							</thead>
						</table>
						<div id="toolbar_proprcdetail" style="height:auto">
							<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" id="btn_append" onClick="append()">添加一行</a>
							<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" onclick="removeit()">移除一行</a>
							<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-ok',plain:true" onclick="accept()">应用</a>
							<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-undo',plain:true" onclick="reject()">撤销</a>
						</div>
					</form>
=======
				width:'70%',
				labelWidth:'60',
				panelWidth: '450',
				panelHeight:'auto',
				url:'findEquipmentSupplierByPage',
				pagination: true,
				pageSize: 10,
				pageList: [5, 10, 15, 20],
				idField: 'equSupplierId',
				textField: 'equSupplierName',
				columns:[[
					      {field:'equSupplierId',title:'供应商ID',checkbox:true,width:60},
					      {field:'equSupplierName',title:'供应商名称',width:100,align:'center'},
					      {field:'equSupplierPhone',title:'供应商电话',width:100,align:'center'},
					      {field:'equSupplierAddress',title:'供应商地址',width:100,align:'center'},
					      {field:'equHead',title:'负责人',width:80,align:'center'}
					    ]] 
			});
			
			$("#equa").combogrid({
				label:'采购员:',
				width:'70%',
				labelWidth:'60',
				panelWidth: '300',
				panelHeight: 'auto',
				url:'findEmpByPage',
				editable: false,
				pagination: true,
				pageSize: 10,
				pageList: [5, 10, 15, 20],
				idField: 'employeeName',
				textField: 'employeeName',
				columns:[[
							 {field:'employeeName',title:'姓名',width:90},
			                 {field:'depName',title:'部门',width:100},
			                 {field:'employeeJob',title:'职位',width:100}
	            		]]
			});
			
		});
	</script>
	<form id="form_equprcdetail" action="do_equprcdetail" method="post">
		<table id="tab_equprcdetail" width="100%" style="background: rgb(236, 243, 255); padding: 10px; border-radius: 5px;">
				<tr>
					<td style="width:33%">
						<input id="equat" class="easyui-datebox" data-options="
								 label:'到货日期:',
								 width:'70%',
								 editable: false,
								 labelWidth:'60'" />
					</td>	
					<td style="width:33%">
						<input id="equa" name="equApprover"/>
					</td>
					<td style="width:33%">
						<select id="equsn" name="equSupplierName"></select>
					</td>
				</tr>
		</table>
		
		<div style="margin: 5px;">
			<div id="tt" class="easyui-tabs" style="width:100%; margin-top: 10px;"
				data-options="plain:true,narrow:true">
				<div title="采购计划明细" style="padding:10px">
					<table id="tab_equprcplan" class="easyui-datagrid" style="height: auto;width:100%" data-options="
								iconCls: 'icon-edit',
								singleSelect: true,
								toolbar: '#toolbar_proprcdetail',
								method: 'get'">
						<thead>
							<tr>
								<th data-options="field:'equName',width:'16%',align:'center',editor:{
										type:'combogrid',
										options:{
										width:'45%',
										labelWidth:'60',
										panelWidth: '290',
										panelHeight: 'auto',
										editable: false,
										url:'findequprplanByequname',
										pagination: true,
										pageSize: 10,
										pageList: [5, 10, 15, 20],
										idField: 'equName',
										textField: 'equName',
										multiple: true,
										fitColumns: true,
										columns:[[
												    {field:'equPrcPlanId',title:'编号',checkbox:true,width:80},
										      		{field:'equName',title:'器械名称',width:100,align:'center'},
										      		{field:'equAppStatus',title:'审批状态',width:100,align:'center'}
										    	]]
										}}">器械名称</th>
									<th data-options="field:'equPrcNumber',width:'16%',editor:'textbox',editor:{type:'numberbox',options:{precision:2}},align:'center'">采购数量</th>
									<th data-options="field:'equExpectedPrice',width:'16%',editor:{type:'numberbox',options:{precision:2}},align:'center'">单价</th>
									<th data-options="field:'equUnit',width:'16%',align:'center',editor:{
												type:'combobox',
												options:{
												valueField:'label',
												textField:'value',
												editable: false,
												panelHeight: 'auto',
												data: [{label:'个',value:'个'},{label:'台',value:'台'},{label:'把',value:'把'}]
														}
												}">单位</th>
									<th data-options="field:'equBatch',width:'16%',align:'center',editor:{
												type:'combobox',
												options:{
												valueField:'label',
												textField:'value',
												editable: false,
												panelHeight: 'auto',
												data: [{label:'1',value:'1'},{label:'2',value:'2'},{label:'3',value:'3'}]
														}
												}">批次</th>
									<th data-options="field:'equSupplierName',width  :'16%',align:'center',editor:{
												type:'combogrid',
												options:{
												panelWidth: '450',
												panelHeight:'auto',
												editable: false,
												url:'findEquipmentSupplierByPage',
												pagination: true,
												pageSize: 10,
												pageList: [5, 10, 15, 20],
												idField: 'equSupplierId',
												textField: 'equSupplierName',
												columns:[[
													      {field:'equSupplierId',title:'供应商ID',checkbox:true,width:60},
													      {field:'equSupplierName',title:'供应商名称',width:100,align:'center'},
													      {field:'equSupplierPhone',title:'供应商电话',width:100,align:'center'},
													      {field:'equSupplierAddress',title:'供应商地址',width:100,align:'center'},
													      {field:'equHead',title:'负责人',width:80,align:'center'}
													    ]]
										}}">供应商</th>
								</tr>
							</thead>
						</table>
						<div id="toolbar_proprcdetail" style="height:auto">
							<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" id="btn_append" onClick="append()">添加一行</a>
							<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" onclick="removeit()">移除一行</a>
							<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-ok',plain:true" onclick="accept()">应用</a>
							<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-undo',plain:true" onclick="reject()">撤销</a>
						</div>
>>>>>>> branch 'tgj' of https://git.oschina.net/xmw1995/HIS.SpringMVC.git
				</div>
			</div>
			
			<div style="margin-top: 10px;">
				<a class="easyui-linkbutton" data-options="iconCls:'icon-ok',onClick: savePlan">提交采购详情</a>
			</div> 
		</div>
	</form>
</body>
</html>